R Sys.Date()library(tidyverse)
library(sf)
ucsfi <- read_sf("data/ucsfi.shp") # %>% `st_crs<-`(3857) # 3857 is Web mercator
brazil0 <- read_sf("data/BRA_adm/BRA_adm0.shp")
In the above code chunk projection is commented out because tmap appears to work beset without the projection assigned. We’ll do that later. assigned with st_crs() using a somewhat non-standard syntax. However, It seemed to be the only way I could add a projection to this particular shapefile. Below are some other syntax examples that have worked for me with other shapefiles. Of course there are various ways to add projection and since this is R, there’s more than one way to accomplish the goal.
sf::st_crs(3857)
sf::st_transform(3857)
ggplot2::coord_sf(crs = 3857) # must use the development version of ggplot2
st_crs(ucsfi)
Coordinate Reference System: NA
print("ucsfi above ^^^ --------- brazil0 below")
[1] "ucsfi above ^^^ --------- brazil0 below"
st_crs(brazil0)
Coordinate Reference System:
EPSG: 4326
proj4string: "+proj=longlat +datum=WGS84 +no_defs"
# or check the projection for an individual polygon ...
# ucsfi$geometry %>% head(1)
as_tibble(ucsfi)
Simple feature collection with 147 features and 13 fields
geometry type: MULTIPOLYGON
dimension: XY
bbox: xmin: -73.99068 ymin: -32.92342 xmax: -32.35011 ymax: 5.272257
epsg (SRID): NA
proj4string: NA